home *** CD-ROM | disk | FTP | other *** search
- /*
- * SFskyedit - Star Fighter 3000 sky colours editor
- * Interpolation dbox
- * Copyright (C) 2001 Chris Bazley
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public Licence as published by
- * the Free Software Foundation; either version 2 of the Licence, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public Licence for more details.
- *
- * You should have received a copy of the GNU General Public Licence
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- /* ANSI library files */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- /* RISC OS library files */
- #include "wimp.h"
- #include "toolbox.h"
- #include "event.h"
- #include "wimplib.h"
- #include "window.h"
- #include "gadgets.h"
-
- /* My library files */
- #include "err.h"
- #include "msgtrans.h"
- #include "Macros.h"
- #include "Pal256.h"
-
- /* Local headers */
- #include "Utils.h"
- #include "EditSky.h"
- #include "Back-end.h"
- #include "Interpolate.h"
- #include "Main.h"
-
- /* Gadgets */
- #define INTERPOLATE_CUSCOL1 0x06
- #define INTERPOLATE_CUSMENU1 0x07
- #define INTERPOLATE_CUSCOL2 0x09
- #define INTERPOLATE_CUSMENU2 0x0a
- #define INTERPOLATE_CANCEL 0x00
- #define INTERPOLATE_GO 0x01
-
- ObjectId Interpolate_sharedid = NULL_ObjectId;
- static char start_col, end_col;
- static bool have_caret;
-
- /* ----------------------------------------------------------------------- */
- /* Function prototypes */
-
- static ToolboxEventHandler _Interpolate_buttonhandler, _Interpolate_colourshandler, _Interpolate_popuphandler, _Interpolate_openhandler;
-
- /* ----------------------------------------------------------------------- */
- /* Public functions */
-
- void Interpolate_initialise(ObjectId object)
- {
- /* Record ID */
- Interpolate_sharedid = object;
-
- /* Install handlers */
- EF(event_register_toolbox_handler(object, ActionButton_Selected, _Interpolate_buttonhandler, NULL));
- EF(event_register_toolbox_handler(pal256_sharedid, Pal256_ColourSelected, _Interpolate_colourshandler, NULL));
- EF(event_register_toolbox_handler(object, PopUp_AboutToBeShown, _Interpolate_popuphandler, NULL));
- EF(event_register_toolbox_handler(object, Window_AboutToBeShown, _Interpolate_openhandler, NULL));
- EF(event_register_toolbox_handler(object, Window_HasBeenHidden, hand_back_caret, &have_caret));
- EF(event_register_wimp_handler(object, -1, watch_caret, &have_caret));
-
- have_caret = false;
- }
-
- /* ----------------------------------------------------------------------- */
- /* Private functions */
-
- static int _Interpolate_openhandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
- {
- /* Dialogue box about to open - set up from ancestor */
- ViewData *view_data;
- char validation[16];
-
- E_RETV(toolbox_get_client_handle(0, id_block->ancestor_id, (void **)&view_data), 1);
-
- start_col = get_shade(&view_data->sky, view_data->selection_start);
- sprintf(validation, "r2;C/%X", (palette[start_col] & 0xffffff00) >> 8);
- RE(button_set_validation(0, id_block->self_id, INTERPOLATE_CUSCOL1, validation));
-
- end_col = get_shade(&view_data->sky, view_data->selection_end);
- sprintf(validation, "r2;C/%X", (palette[end_col] & 0xffffff00) >> 8);
- RE(button_set_validation(0, id_block->self_id, INTERPOLATE_CUSCOL2, validation));
- return 1; /* claim event */
- }
-
- /* ----------------------------------------------------------------------- */
-
- static int _Interpolate_colourshandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
- {
- /* Colour selected by picker */
- Pal256ColourSelectedEvent *pcse = (Pal256ColourSelectedEvent *)event;
- ObjectId parent;
- ComponentId parent_component, button;
- char validation[16];
-
- E_RETV(toolbox_get_parent(0, id_block->self_id, &parent, &parent_component), 0);
- if(parent != Interpolate_sharedid)
- return 0; /* event not handled */
-
- /* Record new colour */
- switch (parent_component) {
- case INTERPOLATE_CUSMENU1:
- start_col = pcse->colour_number;
- button = INTERPOLATE_CUSCOL1;
- break;
- case INTERPOLATE_CUSMENU2:
- end_col = pcse->colour_number;
- button = INTERPOLATE_CUSCOL2;
- break;
- default:
- return 0; /* eh?! */
- }
-
- /* Display new colour */
- sprintf(validation, "r2;C/%X", (palette[pcse->colour_number] & 0xffffff00) >> 8);
- RE(button_set_validation(0, parent, button, validation));
- return 1; /* claim event */
- }
-
- /* ----------------------------------------------------------------------- */
-
- static int _Interpolate_popuphandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
- {
- /* Colour picker about to pop up - set colour */
- switch(id_block->self_component) {
- case INTERPOLATE_CUSMENU1:
- RE(Pal256_set_colour(((PopUpAboutToBeShownEvent *)event)->menu_id, start_col));
- return 1; /* claim event */
- case INTERPOLATE_CUSMENU2:
- RE(Pal256_set_colour(((PopUpAboutToBeShownEvent *)event)->menu_id, end_col));
- return 1; /* claim event */
- }
- return 0; /* event not handled */
- }
-
- /* ----------------------------------------------------------------------- */
-
- static int _Interpolate_buttonhandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
- {
- ActionButtonSelectedEvent *abse = (ActionButtonSelectedEvent *)event;
- ViewData *view_data;
-
- switch(id_block->self_component) {
- case INTERPOLATE_GO:
- E_RETV(toolbox_get_client_handle(0, id_block->ancestor_id, (void **)&view_data), 1);
-
- /* Stupidity checks */
- if(!view_data->selection_exists
- || ((view_data->selection_end+1) - view_data->selection_start) < 2) {
- _kernel_oswrch(7); /* warning beep */
- return 1; /* claim event */
- }
-
- /* Do the business */
- gradient_overwrite(&view_data->sky, view_data->selection_start, view_data->selection_end, start_col, end_col, 3);
- EditSky_rowsupdated(view_data, view_data->selection_start, view_data->selection_end);
- EditSky_markaschanged(view_data);
-
- return 1; /* claim event */
-
- case INTERPOLATE_CANCEL:
- if(FLAG_SET(abse->hdr.flags, ActionButton_Selected_Adjust))
- /* Reset dbox state */
- _Interpolate_openhandler(Window_AboutToBeShown, NULL, id_block, handle);
-
- return 1; /* claim event */
-
- default:
- return 0; /* unknown button */
- }
- }
-